/* eslint-disable */

function numToCh (num) {
    var numList = ['1','2','3','4','5','6','7','8','9']
    var chList = ['一','二','三','四','五','六','七','八','九']
    var index = -1
    for (var i = 0; i < numList.length; i++) {
        if (numList[i] == num) {
            index = i
        }
    }
    if (index == -1) {
        return null
    } else {
        return chList[index]
    }
    
}

function chToNum (ch) {
    var numList = ['1','2','3','4','5','6','7','8','9']
    var chList = ['一','二','三','四','五','六','七','八','九']
    var index = 0
    for (var i = 0; i < chList.length; i++) {
        if (chList[i] == ch) {
            index = i
        }
    }
    return numList[index]
}

function replaceGradeNum (str) {
    var reg = /(\d+)年级/g
    var list = []
    var result = null
    do {
        result = reg.exec(str)
       
        result && list.push(result)

    } while (result)

    
    for (var item of list) {
        var ss = item[1]
        var length = ss.length
        var index = item.index
        var front = str.slice(0, index)
        var center = str.slice(index, index + length)
        var back = str.slice(index + length)
        
       
        
        for (var i = 0; i < center.length; i ++ ) {
            var char = center.charAt(i)
             center = center.replace(char, numToCh(char))
        }
       
        str = front + center + back
    }
    return str
}

function replaceClassNum (str) {
    
    var reg = /([一二三四五六七八九]+)班/g
    var list = []
    var result = null
    do {
        result = reg.exec(str)
      
        result && list.push(result)

    } while (result)

   
    for (var item of list) {
        var ss = item[1]
        var length = ss.length
        var index = item.index
        var front = str.slice(0, index)
        var center = str.slice(index, index + length)
        var back = str.slice(index + length)
        
       
        
        for (var i = 0; i < center.length; i ++ ) {
            var char = center.charAt(i)
             center = center.replace(char, chToNum(char))
        }
       
        str = front + center + back
    }
    return str
}

function formatClass (aaa) {
    
    aaa = replaceGradeNum(aaa)
   
    aaa = replaceClassNum(aaa)
   
    return aaa
}

export default formatClass